var $THUMBNAIL="",$HOMEPIC="",$NEWSID="",$TYPE=1,$STATUS=0,$CATID="",$CATHOME="",$CURRENTCATE="";
window.onload=function(){
	$POSMENU=0
	
	genCat2(0);
	genCat(0);
	resetForm();
	$N("statusnews")[0].value = $STATUS;
	new CHECKLOGIN().check();
}

function preSubmit(action){
	var catidlist = getCheckCatId();
	$N("catidlist")[0].value = catidlist;
	$N("date")[0].value = $N("date")[0].value.replace(",","");
	$N("summary")[0].value = $N("t_summary")[0].value.replace(/\n/g,"<br>").replace(/\r/g,"");
	var _content = tinyMCE.get('elm1').getContent();
	$N("content")[0].value=_content.replace(/\n/g," ").replace(/\r/g," ");
	$N("linkpic")[0].value = $N("img_link")[0].value.replace(/\n/g,",").replace(/\r/g,"");
	var title = $N("title")[0].value;
	var keyword = $N("keyword")[0].value;
	if(catidlist==""){
		alert("Vui lòng chọn chuyên mục");
		return;
	}
	if(title==""){
		 alert("Vui lòng nhập tiêu đề");
		 return;
	}else{
		$N("action")[0].value = action;
		$("loading").style.visibility = "visible";
		keyword=keyword.replace(/'/g,"");
		document.myform.submit();
	}
}
function onAddNews(value, msg){
	if(value=="true"){ 
		alert("Done");
		if(msg!=""&&$N("action")[0].value=="insert"){
			$NEWSID=msg;
		}
		chooseNews($NEWSID);
		if ($TYPESHARE == "auto")
			btnUpdate($AUTONEWSID,'2');
		if ($TYPESHARE == "share")
			btnUpdateShare($AUTONEWSID,'2');
	}else if(value=="false"){
		alert("Đã có lỗi xảy ra. Vui lòng kiểm tra lại thông tin (ngày tháng, tiêu đề,...)");
	}else if(value=="notlogin"){
		alert("Phiên làm việc đã hết hiệu lực. Vui lòng đăng nhập lại");
		window.location = $PN;
	}
	$("loading").style.visibility = "hidden";
}
function chooseNews(newsid){

	if(newsid=="") return;
	try{$("div_"+$NEWSID).style.fontWeight="normal";}catch(e){}
	resetForm();	
	$NEWSID = newsid;
	try{$("div_"+$NEWSID).style.fontWeight="bold";}catch(e){}	
	new NEWS().loadCInfo(newsid);
	$("homepic").innerHTML = "<div id='homepic_"+newsid+"'></div>";
}
function resetForm(){
	document.myform.reset();
	$NEWSID="";
	$N("newsid")[0].value = "";
	$N("remainedfile")[0].value = "";
	$N("oldhomepic")[0].value = "";	
	$("smallpic").innerHTML = "";
	$("homepic").innerHTML = "";
//	var frm=window.frame.rte;
//	var documentB = frm.document;
//	documentB.body.innerHTML= "";
	$("totalnewsdiv").innerHTML = "";
	$("listLinkDiv").style.display="none";
	$CURNGID="";
	
}
function viewLink(){
	var param = $N("linkview")[0].value;
	var newsid = param.split("/")[5];
	chooseNews(newsid);
}

function genCat(type){
	var html = "";
	if($CURRENTCATE!=""){
		$CURRENTCATE=$CURRENTCATE.split("-")[0];
	}
	html = 'Source: <select id="from"><option value="1">VNExpress</option><option value="2">Dân Trí</option><option value="3">Tuổi Trẻ</option><option value="4">Thanh Niên</option><option value="5">Tiền Phong</option></select>';
	html += '<br>Category :<select id="category"><option value="0" selected>All</option><option value="1">Xã hội</option><option value="2">Thế giới</option><option value="3">Kinh tế</option><option value="4">Văn hóa - Nghệ thuật</option><option value="5">Thể thao</option><option value="6">Giáo dục</option><option value="7">Đời sống</option><option value="8">Sức khỏe</option><option value="9">Khoa học - CN</option></select>';
	html += '<br><input type="button" name="Button" value="List" onClick="btnList()" />';
	$("catlist").innerHTML = html;
	if($CURRENTCATE!=""){
		$N("news_catid")[0].value = $CURRENTCATE;	
	}
}

function genCat2(type){
	var html = "";
	if($CURRENTCATE!=""){
		$CURRENTCATE=$CURRENTCATE.split("-")[0];
	}
	if(type=="0"){
	 	html = '<select onChange="search(-1)" style="width:200px"  name="newscat2">' +
	 				'<option value="3-0">Khoa học - Công nghệ</option>' +
					'<option value="7-0">Nghệ thuật</option>' +
					'<option value="9-0">Đời sống</option>' +
					'<option value="10-0">Giải trí</option>' +
					'<option value="2-0">Kinh tế</option>' +
					'<option value="5-0">Thể thao</option>' +
					'<option value="1-0">Xã hội</option>' +
					'<option value="8-0">Sức khỏe</option>' +
					'<option value="6-0">Thế giới</option>' +
					'<option value="4-0">Giáo dục</option>' +
	 				'</select>';
	 	$CURRENTCATE = $CURRENTCATE+"-"+0;
	}else if(type=="2"){
		html = '<select onChange="search(-1)" style="width:200px"  name="newscat2">' +
				'<option value="3-2">Khoa học - Công nghệ</option>' +
				'<option value="7-2">Nghệ thuật</option>' +
				'<option value="9-2">Đời sống</option>' +
				'<option value="10-2">Giải trí</option>' +
				'<option value="2-2">Kinh tế</option>' +
				'<option value="5-2">Thể thao</option>' +
				'<option value="1-2">Xã hội</option>' +
				'<option value="8-2">Sức khỏe</option>' +
				'<option value="6-2">Thế giới</option>' +
				'<option value="4-2">Giáo dục</option>' +
				'</select>';
		 	$CURRENTCATE = $CURRENTCATE+"-"+2;
	}
	$("catlist2").innerHTML = html;
	if($CURRENTCATE!=""){
		$N("newscat2")[0].value = $CURRENTCATE;
	}
	search(-1);
}
ROLONEWS=function(){}

/*ROLONEWS.prototype.listNews=function(catid){
	$("loading").style.visibility = "visible";
	var fncSuc = XHR.Delegate(this,this.listNewsSuc);
	var param = {action:"listAutoNews",catid:catid};
	new XHR("post",fncSuc).send($PN+"/DoAdmin",param);
	this.catid = catid;
}
ROLONEWS.prototype.listNewsSuc=function(r){
	$("loading").style.visibility = "hidden";
	var xml = r.xml;
	
	if(r.text=="notlogin"||checklogin(r.xml)==false){
		window.location = $PN;
		return;
	}
		var il = xml.getElementsByTagName("news");
		if(il.length==0) il = xml.getElementsByTagName("group");
		var img = "",htmlsmall="";
		var type = this.catid.split("-")[1];
		var typeview = "";
		var sourceatt="",totalnews="";
		if(type==0){
			typeview ="cluster";
			sourceatt = "c";
		}else if(type==2){
			typeview ="news";
			sourceatt = "s";
		}
		else if(type==3) typeview ="viewenglishnews";
		for(var i=0; i < il.length; i++){
			if(type==2) totalnews=1;
			else if(type==0) totalnews=il[i].getAttribute("tn");
			var title = (il[i].getAttribute("title")==null) ? il[i].getAttribute("t") : il[i].getAttribute("title");
			img = (il[i].getAttribute("img")==null) ? il[i].getAttribute("i") : il[i].getAttribute("img");
			var desc = (typeview=="cluster") ? il[i].getAttribute("s") : il[i].getAttribute("sm");
			htmlsmall+="<tr><td width=\"100px\" valign=\"top\"><img src=\""+img+"\"  width=\"100\"></td><td valign=\"top\">" +
						"<div  style=\"margin-bottom:4px;border-bottom:1px solid #F0F0F0;padding-bottom:4px\">" +
						"<input type=\"checkbox\" value=\""+il[i].getAttribute("id")+"\" name=\"checkbox_news\" id=\"checkbox_news\" />"+
						"<a href=\""+il[i].getAttribute("l")+"\" style=\"color:#000000\" target=\"_blank\">" +
						title+"</a>" +
						"<div style=\"font-size:11px;color:#999999\">Ngày đăng: "+il[i].getAttribute("d")+"</div>";
						if(type==0)
							htmlsmall+="Id: <input type=\"text\" readonly=\"true\" style=\"width:60px;font-size:11px\" onClick=\"javascript:this.focus();this.select();\" value=\""+il[i].getAttribute("id")+"\"> ("+totalnews+")";
				htmlsmall+="<div id=\"link_"+il[i].getAttribute("id")+"\" style=\"display:none\">"+il[i].getAttribute("l")+"</div>"+
						"<div id=\"source_"+il[i].getAttribute("id")+"\" style=\"display:none\">"+il[i].getAttribute(sourceatt)+"</div>"+
						"<div id=\"total_"+il[i].getAttribute("id")+"\" style=\"display:none\">"+totalnews+"</div>"+						
						"</div></td></tr>";
		}
	if(htmlsmall!="")
		$("auto_newslist").innerHTML = "<table cellpadding=\"3\" cellspacing=\"3\">"+htmlsmall+"</table>";
	else
		$("auto_newslist").innerHTML = "<div align='center' padding='3px'><b>Chưa có dữ liệu</b></div>";
}*/

ROLONEWS.prototype.addAutoNews=function(newsidlist,linklist,totalnews,source,tempcat){
	$("update_btn").disabled = true;
	$("loading").style.visibility = "visible";
	var fncSuc = XHR.Delegate(this,this.addAutoNewsSuc);
	var type = $N("news_catid")[0].value.split("-")[1];
	var param = {action:"addAutoNews",newsidlist:newsidlist,type:type,linklist:linklist,totalnews:totalnews,source:source,tempcat:tempcat};
	new XHR("post",fncSuc).send($PN+"/DoAdmin",param);
}
ROLONEWS.prototype.addAutoNewsSuc=function(r){
	$("update_btn").disabled = false;
		$("loading").style.visibility = "hidden";
		var xml = r.xml;
	if(checklogin(r.xml)==false){
		window.location = $PN;
		return;
	}
		if(getRV(xml)){
			window.parent.listNews(-1);
			var l = $N("checkbox_news");
			for(var j=0; j < l.length; j++){
				$N("checkbox_news")[j].checked =false;
			}
			search(-1);
			alert("Done");
		}else{
			alert("Cập nhật thất bại");
		}
}
function makeLinkImg(link){
	return "http://news.rolo.vn/news/Img?link="+encodeURIComponent(link);
}
function listNews(){
	var catid = $N("news_catid")[0].value;
	$CURRENTCATE = catid;
	//new ROLONEWS().listNews(catid);
}

function add(){
	var l = $N("checkbox_news");
	var newsid = "",content = "";
	var linklist = "",sourcelist="",totalnews="";
	for(var j=0; j < l.length; j++){
		if($N("checkbox_news")[j].checked ==true){
			newsid += $N("checkbox_news")[j].value+",";
			linklist +=$("link_"+$N("checkbox_news")[j].value).innerHTML+",";
			totalnews +=$("total_"+$N("checkbox_news")[j].value).innerHTML+","
			sourcelist +=$("source_"+$N("checkbox_news")[j].value).innerHTML+",";
		}
	}
	if(newsid!=""){
		if(newsid.split(",").length>40){
			alert("Mỗi lần chỉ được chọn tối đa 40 tin");
			return;
		}
		newsid = newsid.substring(0,newsid.length-1);
		linklist = linklist.substring(0,linklist.length-1);
		sourcelist =sourcelist.substring(0,sourcelist.length-1);
		totalnews = totalnews.substring(0,totalnews.length-1);
		new ROLONEWS().addAutoNews(newsid,linklist,totalnews,sourcelist,$N("news_catid")[0].value.split("-")[0]);
	}
	else return
}


NEWS=function(){}
NEWS.prototype.search=function(page){
	this.page = page;
	var fncSuccess = XHR.Delegate(this,this.searchSuccess);
	var catid = $N("newscat2")[0].value.split("-")[0];
	var param = {action:"listNews",page:page,type:$TYPE,status:$STATUS,catid:catid};
	new XHR("post",fncSuccess).send($PN+"/DoAdmin",param);
}
NEWS.prototype.searchSuccess=function(r){
	var xml = r.xml;
	if(checklogin(xml)==false){
		window.location = $PN;
		return;
	}
	if(getRV(xml)){
		if(this.page==-1){
			var p = xml.getElementsByTagName("page");
			var total = p[0].getAttribute("record");
			$("totalSP").innerHTML = total + " kết quả";
			var page = new Page("pagebreak1","pagebreak2",p[0].getAttribute("totalpage"),search,1,"pagebreak");
			page.show();
		}
		var html="",poster;
		var il = xml.getElementsByTagName("news");
	
		for(var i=0; i < il.length; i++){
			poster = il[i].getAttribute("poster");
			if(poster!="null" && poster!=""){
				poster = "<div>Poster: "+poster+"</div>"
			}
			html += "<div class=\'list1\' style=\'cursor:pointer;font-size:14px\' id=\"div_"+il[i].getAttribute("newsid")+"\" onClick=\"chooseNews('"+il[i].getAttribute("newsid")+"')\">" +
					"<table><tr><td width=\'70px\' valign=\'top\'>"+
					"<img width=\'70px\' src=\'"+genLinkImg(il[i].getAttribute("newsid"),il[i].getAttribute("thumbnail"))+"\'>"+
					"</td><td valign=\'top\'>"+
					il[i].getAttribute("title")+
					"<div style=\'font-size:11px;color:#933\'>Ngày đăng: "+fulldateSQLtoN(il[i].getAttribute("createddate"))+"</div>"
					+poster
					+"</td></tr></table>"+
					"</div>";
		}
		if(html!=""){
			$("listnews").innerHTML=html;
			try{
				$("div_"+$CUREVENT).style.fontWeight="bold";
			}catch(e){}
		}
		else
			$("listnews").innerHTML="<div align='center'><b>Chưa có dữ liệu!</b></div>";
	}else{
		$("listnews").innerHTML="Lỗi rồi";
	}
}
NEWS.prototype.loadCInfo=function(newsid){ //load common info for edit;
	var fncSuccess = XHR.Delegate(this,this.loadCInfoSuccess);
	var param = {action:"getNewsDetail",newsid:newsid};
	new XHR("post",fncSuccess).send($PN+"/DoAdmin",param);
}
NEWS.prototype.loadCInfoSuccess=function(r){
	var xml = r.xml;
	if(checklogin(xml)==false){
		window.location = $PN;
		return;
	}
	var item = xml.getElementsByTagName("item")[0];
//	try{
		if(getRV(xml)){
			$N("newsid")[0].value = item.getAttribute("newsid");
			$N("title")[0].value = item.getAttribute("title");
			
			$N("t_summary")[0].value = textToArea(item.getAttribute("description"));
			$N("date")[0].value = fulldateSQLtoN(item.getAttribute("createddate"));
			$N("link")[0].value = item.getAttribute("link").replace(/&amp;/g,"&");
			$N("source")[0].value = item.getAttribute("source");
			$N("keyword")[0].value = item.getAttribute("keyword");
			$N("oldhomepic")[0].value = item.getAttribute("homepic");
			var cat = item.getAttribute("catid");
			$THUMBNAIL = item.getAttribute("thumbnail")
			checkCatId(cat);
			$CONTENT=unparse(item.getAttribute("content"));
			$N("remainedfile")[0].value = item.getAttribute("picturefilename");
			//window.setTimeout("var frm=window.frames.rte;var documentB = frm.document;tinyMCE.execCommand('mceInsertContent',false,'$CONTENT');",500);
			tinyMCE.activeEditor.setContent($CONTENT);

			if(item.getAttribute("picturefilename")!=""){
				var l = item.getAttribute("picturefilename").split(",");
				var html = "";
				for(var i=0; i < l.length; i++){
					if(i>=6)html+="<br>";
					html +=genImg(item.getAttribute("newsid"),l[i]);
				}
				$("smallpic").innerHTML=html;
			}
			
			$("homepic_"+$NEWSID).innerHTML = listHomePic($NEWSID,item.getAttribute("homepic"));
			
			$HOMEPIC = item.getAttribute("homepic");
			try{$("file_"+$THUMBNAIL.replace("thumb.",".")).checked = true;}catch(e){}
			try{$("filehome_"+$HOMEPIC.replace("home.",".")).checked = true;}catch(e){}	
			$("viewOrgPage").href = item.getAttribute("link").replace(/&amp;/g,"&");
			$("viewPage").href = makeLinkViewNews(item.getAttribute("newsid"),item.getAttribute("utitle"));
			$("user_post").innerHTML = item.getAttribute("poster");
				$("totalnewsdiv").innerHTML = "<span id='totalnews'>"+item.getAttribute("totalnews")+"</span> <span style=\"cursor:pointer\" onClick=\"viewNewsGroup('"+$NEWSID+"')\">[Chi tiết]</span>";
		}else{
			if(xml.getElementsByTagName("root")[0].getAttribute("value")=="empty"){
				alert("Bạn không có quyền xem bài viết này");
			}
		}
//	}catch(e){
//		
//	}

}
NEWS.prototype.deleteImg=function(newsid,filename,filelist){ //load common info for edit;
	var fncSuccess = XHR.Delegate(this,this.deleteImgSuccess);
	var param = {action:"deleteFileImg",newsid:newsid,filename:filename,filelist:filelist};
	new XHR("post",fncSuccess).send($PN+"/DoAdmin",param);
	this.newsid = newsid;
}
NEWS.prototype.deleteImgSuccess=function(r){
	var xml = r.xml;
	if(checklogin(xml)==false){
		window.location = $PN;
		return;
	}
	var item = xml.getElementsByTagName("ret")[0];
	$N("remainedfile")[0].value = item.getAttribute("value");
	var l = item.getAttribute("value").split(",");
		var html = "";
		for(var i=0; i < l.length; i++){
			if(i>=5)html+="<br>";
			html+=genImg(this.newsid,l[i]);
		}
		$("smallpic").innerHTML=html;
		try{$("file_"+$THUMBNAIL.replace("thumb.",".")).checked = true;}catch(e){}
}
NEWS.prototype.updateThumb=function(newsid,filename,oldfilename){ //load common info for edit;
	var fncSuccess = XHR.Delegate(this,this.updateThumbSuccess);
	var param = {action:"updateThumb",newsid:newsid,filename:filename,oldfilename:oldfilename};
	new XHR("post",fncSuccess).send($PN+"/DoAdmin",param);
}
NEWS.prototype.updateThumbSuccess=function(r){
	var xml = r.xml;
	if(checklogin(xml)==false){
		window.location = $PN;
		return;
	}
	if(getRV(xml)){
		alert("done");
	}else{
		alert("Fail");
	}
}

NEWS.prototype.clearAllCacheHome=function(){ //load common info for edit;
	var fncSuccess = XHR.Delegate(this,this.clearAllCacheHomeSucc);
	var param = {action:"clearAllCache"};
	new XHR("post",fncSuccess).send($PN+"/DoAdmin",param);
}
NEWS.prototype.clearAllCacheHomeSucc=function(r){
	var xml = r.xml;
	if(checklogin(xml)==false){
		window.location = $PN;
		return;
	}
	if(getRV(xml)){
		alert("done");
	}else{
		alert("Fail");
	}
}


NEWS.prototype.updateHomePic=function(newsid,filename){ //load common info for edit;
	var fncSuccess = XHR.Delegate(this,this.updateHomePicSuccess);
	var param = {action:"updateHomePic",newsid:newsid,filename:filename};
	new XHR("post",fncSuccess).send($PN+"/DoAdmin",param);
}
NEWS.prototype.updateHomePicSuccess=function(r){
	var xml = r.xml;
	if(r.text=="notlogin"){
		window.location = $PN;
		return;
	}
	if(checklogin(xml)==false){
		window.location = $PN;
		return;
	}
	if(getRV(xml)){
		alert("done");
	}else{
		alert("Fail");
	}
}

NEWS.prototype.deleteNews=function(newsid){ //load common info for edit;
	var fncSuccess = XHR.Delegate(this,this.deleteNewsSuccess);
	var param = {action:"deleteNews",newsid:newsid};
	new XHR("post",fncSuccess).send($PN+"/DoAdmin",param);
}
NEWS.prototype.deleteNewsSuccess=function(r){
	var xml = r.xml;
	if(checklogin(xml)==false){
		window.location = $PN;
		return;
	}
	if(getRV(xml)){
		resetForm();
		search(-1);
	}else{
		alert("Fail");
	}
}
NEWS.prototype.updateStatus=function(newsid,status){ //load common info for edit;
	var fncSuccess = XHR.Delegate(this,this.updateStatusSuccess);
	var param = {action:"updateStatus",status:status,newsid:newsid};
	new XHR("post",fncSuccess).send($PN+"/DoAdmin",param);
}
NEWS.prototype.updateStatusSuccess=function(r){
	var xml = r.xml;
	if(checklogin(xml)==false){
		window.location = $PN;
		return;
	}
	if(getRV(xml)){
		resetForm();
		search(-1);
	}else{
		alert("Fail");
	}
}

NEWS.prototype.changeToTopNews=function(newsid,groupid,title,sum,source,link,date,total){ //load common info for edit;
	var fncSuccess = XHR.Delegate(this,this.changeToTopNewsSuccess);
	var param = {action:"changeTopToLatest",latestId:newsid,topId:groupid,title:title,
				sum:sum,source:source,link:link,date:date,total:total};
	new XHR("post",fncSuccess).send($PN+"/DoAdmin",param);
	this.groupId = newsid;
}
NEWS.prototype.changeToTopNewsSuccess=function(r){
	var xml = r.xml;
	$("changebtn").disabled=false;
	if(checklogin(xml)==false){
		window.location = $PN;
		return;
	}
	if(getRV(xml)){
		viewNewsGroup(this.groupId);
	}else{
		alert("Fail");
	}
}

NEWS.prototype.getFromArt=function(){ //load common info for edit;
	var fncSuccess = XHR.Delegate(this,this.getFromArtSuc);
	var param = {action:"getNewsFromArt"};
	new XHR("post",fncSuccess).send($PN+"/DoAdmin",param);
}
NEWS.prototype.getFromArtSuc=function(r){
	var xml = r.xml;
	$("getart").disabled=false;
	if(checklogin(xml)==false){
		window.location = $PN;
		return;
	}
	if(getRV(xml)){
		var l = xml.getElementsByTagName("status")[0].getAttribute("value");
		$("artStatus").innerHTML = "NGHỆ THUẬT: "+ l.split("_")[0]+"<br>KHCN: "+l.split("_")[1]+"<BR>SỨC KHỎE: "+l.split("_")[2];
		alert("Done");
	}else{
		alert("Fail");
	}
}




NEWS.prototype.addHome=function(newsId,type){
	$("loading").style.visibility = "visible";
	var fncSuc = XHR.Delegate(this,this.addHomeSuc);
	var param = {action:"addHome",newsId:newsId,catId:$CATHOME,type:type};
	new XHR("post",fncSuc).send($PN+"/DoAdmin",param);
}
NEWS.prototype.addHomeSuc=function(r){
	$('add_HomeDiv').style.display='none';
	var xml = r.xml;
	var html = "";
	if(getRV(xml)){
		alert("Done");
	}else{
		alert("Đã có rồi");
	}
}

function addHomeNews(){
	if($NEWSID=="") return;
	new NEWS().addHome($NEWSID,1);
}

function updateStatus(newsid,status){
	new NEWS().updateStatus(newsid,status);
}
function deleteNews(newsid){
	if(newsid=="") return;
	if(confirm("Bạn có chắc muốn xóa?")){
		new NEWS().deleteNews(newsid);
	}
}
function updateThumb(newsid,filename){
	new NEWS().updateThumb(newsid,filename,$THUMBNAIL);
}
function updateHomePic(newsid,filename){
	new NEWS().updateHomePic(newsid,filename,$HOMEPIC);
}

function search(page){
	new NEWS().search(page);
}
function deleteImg(newsid,filename){
	var list = $N("remainedfile")[0].value;
	new NEWS().deleteImg(newsid,filename,list);
}
function genImg(newsid,file){
	var html = "<div style='float:left;width:100px;margin-right:3px;padding-bottom:5px'>" +
					"<div style='padding:1px;border:1px solid #cccccc;width:100px;height:82px;background-color:#FFFFFF;position: relative;overflow:hidden'>" +
							"<img class='thumbimg' src='"+genLinkImg(newsid,file)+"'>" +
							"<div align='left' style='position: absolute; top: 0px; left: 0px;font-size:11px;'>" +
							"<input type='radio' name='radio' onClick='updateThumb(\""+newsid+"\",\""+file+"\")' id='file_"+file+"' value='file_"+file+"'/>Thumbnail<br>" +
							"<div><img src='images/deleteimg.gif' onClick='deleteImg(\""+newsid+"\",\""+file+"\")' style='cursor:pointer;'></div>"+
							"</div>" +
					"</div>"+
					"<input type='text' style='width:98px' onclick='javascript:this.focus();this.select();' readonly='true' value='"+genLinkImg(newsid,file)+"'>"+
				"</div>";
	return html;
}

function changeTypeNews(){
	$STATUS = $N("statusnews")[0].value;
	if($STATUS=="1"){
		$("publishBtn").disabled=false;
		$("noPublishBtn").disabled=false;
	}else{
		$("noPublishBtn").disabled=false;
		$("publishBtn").disabled=false;
	}
	search(-1);
}
function chooseTab(i){
	$("autonewsdiv").style.display="none";
	$("handmadediv").style.display="none";
	$("usernewsdiv").style.display="none";
	$("text_auto").style.textDecoration="";
	$("text_hand").style.textDecoration="";
	$("text_user").style.textDecoration="";
	if(i==0){
		$("autonewsdiv").style.display="block";
		$("text_auto").style.textDecoration="underline";
	}else if (i==1){
		$("text_hand").style.textDecoration="underline";
		$("handmadediv").style.display="block";
	}else if(i==2) {
		$("usernewsdiv").style.display="block";
		$("text_user").style.textDecoration="underline";
	}
}
function clickContrains(iddest){
	$("cat"+iddest).checked = true;
}
function checkAll(){
	var c = $N("checkbox_news");
	var sourcheck = $("scheck").checked;
	for(var i=0; i < c.length; i++){
		$N("checkbox_news")[i].checked = sourcheck;
	}
}
function changeToTopNews(){
	var newsid = $NEWSID;
	var groupId = $N("topnewslink")[0].value;
	var title = $N("title")[0].value;
	var sum = $N("t_summary")[0].value.replace(/\n/g,"<br>").replace(/\r/g,"");
	var date = $N("date")[0].value;
	var link = $N("link")[0].value;
	var source = $N("source")[0].value;
	var total = $("totalnews").innerHTML;
	if(groupId!=""){
		$("changebtn").disabled=true;
		new NEWS().changeToTopNews(newsid,groupId,title,sum,source,link,date,total);
	}
}
function getFromArt(){
	$("getart").disabled=true;
	new NEWS().getFromArt();
}